package com.lcache.worker;

import com.lcache.common.config.ConfigReader;
import com.lcache.worker.server.WorkerServer;
import com.lcache.worker.service.init.WebSocketChannelInitializer;
import com.lcache.worker.service.init.WebSocketServiceRegistry;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * @program: lcache
 * @description:
 * @author: Alex Wu
 * @createDate: 2025-04-23 10:40
 **/

@Slf4j
public class WorkerBootStrap {

    public static void main(String[] args){
        try {
            CuratorFramework client = CuratorFrameworkFactory.newClient(
                    ConfigReader.getInstance().getOrDefault("zookeeper.address", String.class, "localhost:2181"),
                    new ExponentialBackoffRetry(1000, 3)
            );
            client.start();

            WebSocketServiceRegistry registry = new WebSocketServiceRegistry(client, "localhost", ConfigReader.getInstance().getOrDefault("server.port", Integer.class, 8090));
            registry.register();

            log.info("IM服务启动..");
            // 启动IM服务
            new WorkerServer().start();

        }catch (Exception e) {
            e.printStackTrace();
        }


    }
}